﻿///form表单验证、提交
var formAjax = !function ($) {
    $.fn.BindFormAjax = function () {
        var form = $(".form");
        var acion = $(form).attr("action");
 
            jQuery(".form").validate({
                //当点击提交按钮时执行submitHandler函数
                submitHandler: function (form) {
                    jQuery(form).ajaxSubmit({
                        url: acion,
                        data: jQuery(form).formSerialize(),
                        type: 'POST',
                        beforeSubmit: function () {
                            $(".formsubmit").dialog('处理中，请稍等...');
                        },
                        success: function (data) {
                            var _resllt = data.Result;
                            var _returnurl = data.Url;
                            var _msg = data.msg;
                            if (_resllt == "success") {
                                $(".formsubmit").dialog(_msg);
                                setTimeout('location.href ="' + _returnurl + '"', 2500);///成功后跳转
                            }
                            else {
                                $(".formsubmit").dialog(_msg);
                                if (_returnurl.indexOf("login") >= 0) {
                                    setTimeout('location.href ="' + _returnurl + '"', 2500);///未登录时跳转
                                }
                            }
                        }
                    });
                    //当验证没通过时不予以提交表单
                    return false;
                }
            });
        }





}(jQuery);


///弹出层封装///
!function ($) {
    $.fn.dialog = function (mes) {
        var defaults = {
            boxTitle: "提示信息"
        };
        var options = $.extend(defaults);
        layer.msg(mes, {
            time: 3000
        });
    }
}(jQuery);



$(function (data) {
    $("button[type='submit']").on("click", function () {
        $(this).BindFormAjax();
    });

   
    $(".shoulder").css({ display: "none" });
    $(".smalljoints").css({ display: "none" });

    $(".leftslide a").on("click", function () {
        var fid = $(this).attr("fid");
        $(this).parent().css({ background: "#ffffff" });
        $(this).parent().siblings().css({ background: "#f0f0f0" });
        $("ul[fid=" + fid + "]").css({ display: "block" });
        $("ul[fid=" + fid + "]").siblings().css({ display: "none" });
        $("#myform input").val("");

    });

    $(".rightslide a").on("click", function () {
        var type = $(this).attr("type");
        var fid = $(this).attr("id");
        $(this).parent().css({ background: "#ffffff" });
        $(this).parent().siblings().css({ background: "#f0f0f0" });
        $("." + type + "").css({ display: "block" });
        switch (type) {
            case "knee":
                $(".shoulder").css({ display: "none" });
                $(".smalljoints").css({ display: "none" });
                break;
            case "shoulder":
                $(".smalljoints").css({ display: "none" });
                $(".knee").css({ display: "none" });
                break;
            case "smalljoints":
                $(".shoulder").css({ display: "none" });
                $(".knee").css({ display: "none" });
                break;

        }

        $("a[fid=" + fid + "]").click();
    });



    $(".leftslide a").eq(0).click();
    $(".rightslide a").eq(0).click();
});